package com.billing.servlet;

import com.billing.config.ServiceConfig;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

public class SystemInitServlet extends HttpServlet {

    public void init(ServletConfig conf) throws ServletException {
        super.init(conf);
        String tt = Thread.currentThread().getContextClassLoader().getResource("/").getPath();
        InputStream is = null;
        String webInfDir = tt.substring(0, tt.lastIndexOf("/classes"));
        System.out.println("app path: " + tt);
        /** 初始化系统配置 **/
        String path = webInfDir + "/config";

        Properties config = new Properties();
        try {
            File configFile = new File(path + File.separator + "config.properties");
            //Properties config = new Properties();
            is = new FileInputStream(configFile);
            config.load(is);
        } catch (Exception e) {
            System.out.println("app start failed:" + e.getMessage());
            return;
        } finally {
            try {
                is.close();
            } catch (Exception e) {
            }
        }

        ServiceConfig.fileUploadPath = config.getProperty("fileUploadPath");
        ServiceConfig.webServiceUrl = config.getProperty("webServiceUrl");

    }
}
